home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: Beginer C please help me
- Date: 20 Mar 1996 21:38 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <20MAR199621383426@erich.triumf.ca>
- References: <DoLCFx.B7x.0.bloor@torfree.net>
- NNTP-Posting-Host: erich.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <DoLCFx.B7x.0.bloor@torfree.net>, bz786@torfree.net (Sherif Asif) writes...
- >This may be a stupid mistake but "please help" me.
-
- >#include <stdio.h>
- >#include <math.h>
- >main ()
- >{
- >float n;
- >n=(9/5);
- >printf ("n= %1.3f\n", n);
- >}
- >I have complied and run the programme & I got the answer n=1.000
- >but Iam supposed to get answer 1.8.
- >Why I got this answer?
-
- 9 and 5 are integers, so the division will be done as an int operation - the
- result will also be an int.
-
- You can make this work as you want by making at least one of the operands a
- float like: 9.0/5.0 - this will do a float division, with a float result.
-
-
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
- or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
-
-
-
-
-
-